<!--
 描述: 登录模板
 作者: Jack Chen
 日期: 2020-04-18
-->

<template>
  <div class="login-container">
    <div class="middelBox">
      <!-- 上 -->
      <div class="navBox">
        <img
          src="https://files.axshare.com/gsc/E0EL5C/fd/21/59/fd2159f2f7f94050a3ed7c0fb1c4079a/images/%E7%99%BB%E5%BD%95/u55.png?pageId=eeeecfe0-1896-412a-b043-26aa33765926"
          alt=""
        />
        <div class="topInfo">
          <span>广西民族大学热泵可视化系统</span
          ><span>Business Data Display Visualization System</span>
        </div>
      </div>
      <div class="formBox">
        <img
          src="https://files.axshare.com/gsc/E0EL5C/fd/21/59/fd2159f2f7f94050a3ed7c0fb1c4079a/images/%E7%99%BB%E5%BD%95/u5.svg?pageId=eeeecfe0-1896-412a-b043-26aa33765926"
          alt=""
        /><img
          src="https://files.axshare.com/gsc/E0EL5C/fd/21/59/fd2159f2f7f94050a3ed7c0fb1c4079a/images/%E7%99%BB%E5%BD%95/u4.svg?pageId=eeeecfe0-1896-412a-b043-26aa33765926"
          alt=""
        /><img
          src="https://files.axshare.com/gsc/E0EL5C/fd/21/59/fd2159f2f7f94050a3ed7c0fb1c4079a/images/%E7%99%BB%E5%BD%95/u6.svg?pageId=eeeecfe0-1896-412a-b043-26aa33765926"
          alt=""
        />
        <div class="realForm">
          <div class="loginTip">
            <div class="left">
              <span></span><span>用户登录</span><span>USER LOGIN</span>
            </div>
            <div
              class="right"
              @mouseenter="floating = true"
              @mouseleave="floating = false"
            >
              登录说明
            </div>
          </div>
          <!-- 提示 -->
          <div class="descri" v-show="floating">
            <p>需验证账号密码完成登录</p>
            <p>账号：admin</p>
            <p>密码：123456</p>
          </div>
          <div class="inputOne">
            <span></span>
            <input
              type="text"
              placeholder="请输入用户名称"
              v-model="userName"
              @blur="inputOff = false"
              @focus="inputOff = true"
            />
            <span v-show="inputOff"></span>
          </div>
          <div class="inputtwo">
            <span></span>
            <input
              type="password"
              placeholder="请输入登录密码"
              v-model="userPwd"
              @blur="inputOff2 = false"
              @focus="inputOff2 = true"
            />
            <span v-show="inputOff2"></span>
          </div>
          <div class="codeBox">
            <div class="addCon">
              <div
                class="slider"
                @mousedown="handleDown"
                :style="{ left: processX + 'px' }"
              >
                <div
                  :class="{ animal: true, stopOrplay: content != '验证成功' }"
                >
                  <div class="anbox" v-for="item in 3" :key="item">
                    <span></span>
                  </div>
                </div>
              </div>
              <div
                class="processBox"
                :style="{ width: processX + 10 + 'px' }"
              ></div>
              <div class="endTip">
                {{ content }}
              </div>
            </div>
          </div>
          <div class="contralTip">
            <div><span></span><span>记住密码</span></div>
            <div>忘记密码？</div>
          </div>
          <div class="loginBtn" @click="login">
            登录
          </div>
          <div class="errorTip">
            {{ modalContent }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  components: {},
  data() {
    return {
      userName: "admin",
      userPwd: "123456",
      visible: false,
      modalContent: "",
      isPress: false,
      beginX: 0,
      processX: 0,
      minX: 278,
      content: "按住滑块向右滑动验证",
      inputOff: false,
      inputOff2: false,
      floating: false,
    };
  },
  computed: {
    isLoginAble() {
      return !(this.userName && this.userPwd);
    },
  },
  created() {},
  mounted() {
    document.addEventListener("mousemove", this.handleMove);
    document.addEventListener("mouseup", this.handleUp);
  },
  beforeDestroy() {
    document.removeEventListener("mousemove", this.handleMove);
    document.removeEventListener("mouseup", this.handleUp);
  },
  methods: {
    handleUp(e) {
      if (this.isPress) {
        this.isPress = false;
        // console.log("抬起", e.clientX - this.beginX);
        this.processX = e.clientX - this.beginX;
        if (this.processX < this.minX) {
          this.processX = 0;
          this.content = "按住滑块向右滑动验证";
        } else {
          this.content = "验证成功";
          this.modalContent = "";
        }
      }
    },
    handleMove(e) {
      if (this.isPress) {
        this.processX = e.clientX - this.beginX;
        if (this.processX >= this.minX) {
          this.processX = 278;
          this.content = "验证成功";
          this.isPress = false;
          this.modalContent = "";
        }
      }
    },
    handleDown(e) {
      if (this.content == "验证成功") {
        return;
      }
      this.processX = 0;
      this.content = "按住滑块向右滑动验证";
      this.isPress = true;
      this.beginX = e.clientX;
    },
    login() {
      if (this.userName == "admin" && this.userPwd == "123456") {
        if (this.content != "验证成功") {
          this.modalContent = "请滑动到正确位置进行验证";
          return;
        }
        this.modalContent = "";
        this.$router.push({
          path: "/layout",
        });
      } else {
        if (!this.userName) {
          this.modalContent = "请填写用户账号";
          return;
        }
        if (!this.userPwd) {
          this.modalContent = "请填写登录密码";
          return;
        }
        this.modalContent = "请填写正确账号和密码";
      }
    },
    confirm() {
      this.visible = false;
      //   console.log('点击确定')
    },
  },
};
</script>

<style lang="scss" scoped>
.login-container {
  background-color: rgba(6, 23, 3, 1);
  height: 100vh;
  position: relative;
  .middelBox {
    position: absolute;
    width: 580px;
    left: 50%;
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
    .formBox {
      margin-top: 20px;
      height: 618px;
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      .realForm {
        width: 487px;
        height: 490px;
        // background-color: red;
        position: relative;

        .inputOne {
          position: absolute;
          top: 50px;
          left: 0px;
          width: 100%;
          height: 65px;
          display: flex;
          align-items: center;
          border: 1px solid rgba(60, 220, 210, 0.3);
          box-sizing: border-box;
          justify-content: space-between;
          span {
            width: 8px;
            height: 12px;
            border: 2px solid #3cdcd2;
            margin: 0 20px;
          }
          span:last-child {
            width: 8px;
            height: 12px;
            border: 2px solid #ccc;
            margin: 0 20px;
          }
          input {
            flex: 1;
            outline: none;
            border: none;
            padding: 0;
            height: 100%;
            font-size: 16px;
            padding: 0 20px;
            box-sizing: border-box;
            color: #fff;
            background: none;
          }
          input:-webkit-autofill {
            transition: background-color 5000s ease-in-out 0s;
          }
          input::placeholder {
            color: #517174;
          }
        }
        .codeBox {
          position: absolute;
          top: 310px;
          left: 0px;
          width: 340px;
          height: 42px;
          color: #fff;
          .addCon {
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
            border: 1px solid rgba(60, 220, 210, 0.3);
            border-radius: 5px;
            box-sizing: border-box;
            .slider {
              width: 60px;
              height: 40px;
              background-color: #50c8be;
              position: absolute;
              top: 0px;
              left: 0px;
              z-index: 3;
              border-radius: 5px;
              display: flex;
              align-items: center;
              justify-content: center;
              overflow: hidden;
              .animal {
                height: 40px;
                top: 0px;
                right: 0px;
                display: flex;
                position: absolute;
                .anbox {
                  width: 60px;
                  height: 40px;
                  display: flex;
                  justify-content: center;
                  align-items: center;

                  span {
                    width: 4px;
                    height: 8px;
                    border: 2px solid #fff;
                  }
                }
              }
              .stopOrplay {
                animation: autoplay 5s ease infinite;
              }
              @keyframes autoplay {
                0% {
                  /* 在前25%的时间内停留在第一个项目上 */
                  transform: translateX(0px);
                }
                50% {
                  /* 在接下来的25%时间内滚动到第二个项目，并在结束时停留 */
                  transform: translateX(60px);
                }
                100% {
                  /* 在接下来的25%时间内滚动到第三个项目，并在结束时停留 */
                  transform: translateX(120px);
                }
              }
            }
            .processBox {
              width: 0px;
              height: 40px;
              background-color: #2a6266;
              position: absolute;
              top: 0px;
              left: 0px;
              z-index: 1;
            }
            .endTip {
              width: 100%;
              height: 40px;
              text-align: center;
              line-height: 40px;
              background-color: transparent;
              position: absolute;
              top: 0px;
              left: 0px;
              z-index: 2;
            }
          }
        }
        .errorTip {
          position: absolute;
          bottom: 10px;
          left: 0px;
          width: 100%;
          color: #e07b1f;
        }
        .loginBtn {
          position: absolute;
          top: 380px;
          left: 0px;
          width: 100%;
          height: 65px;
          background-color: #50c8be;
          text-align: center;
          line-height: 65px;
          color: #fff;
          border-radius: 2px;
          // display: flex;
          // justify-content: space-between;
          // align-items: center;
        }
        .loginBtn:hover {
          background-color: #43aaa3;
          color: rgba(255, 255, 255, 0.5);
        }
        .contralTip {
          position: absolute;
          top: 240px;
          left: 0px;
          width: 100%;
          height: 40px;
          // background-color: yellow;
          display: flex;
          justify-content: space-between;
          align-items: center;
          > div {
            display: flex;
            flex-wrap: nowrap;
            align-items: center;
            span:nth-of-type(1) {
              width: 10px;
              height: 14px;
              margin: 0 10px 0px 20px;
              border: 2px solid #969890;
              box-sizing: border-box;
              // background-color: pink;
            }
          }
        }
        .inputtwo {
          position: absolute;
          top: 145px;
          left: 0px;
          width: 100%;
          height: 65px;
          // background-color: yellow;
          display: flex;
          align-items: center;
          border: 1px solid rgba(60, 220, 210, 0.3);
          box-sizing: border-box;
          justify-content: space-between;
          span {
            width: 8px;
            height: 12px;
            border: 2px solid #3cdcd2;
            margin: 0 20px;
          }
          span:last-child {
            width: 8px;
            height: 12px;
            border: 2px solid #ccc;
            margin: 0 20px;
          }
          input {
            flex: 1;
            outline: none;
            border: none;
            padding: 0;
            height: 100%;
            font-size: 16px;
            padding: 0 20px;
            box-sizing: border-box;
            color: #fff;
            background: none;
          }
          input:-webkit-autofill {
            transition: background-color 5000s ease-in-out 0s;
          }
          input::placeholder {
            color: #517174;
          }
        }
        .descri {
          width: 200px;
          height: 100px;
          z-index: 4;
          position: absolute;
          top: 20px;
          right: 0px;
          background-image: url("https://files.axshare.com/gsc/E0EL5C/fd/21/59/fd2159f2f7f94050a3ed7c0fb1c4079a/images/%E7%99%BB%E5%BD%95/%E8%83%8C%E6%99%AF_u53.svg?pageId=eeeecfe0-1896-412a-b043-26aa33765926");
          background-repeat: no-repeat;
          background-size: 100% 100%;
          background-color: rgba(0, 0, 0, 0);
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          padding: 0 10px;
          padding-top: 12px;
          box-sizing: border-box;
          p {
            width: 100%;
          }
        }
        .loginTip {
          position: absolute;
          top: 0px;
          left: 0px;
          width: 100%;
          height: 20px;
          display: flex;
          align-items: flex-end;
          justify-content: space-between;
          .left {
            display: flex;
            span {
              color: #33bcb5;
              height: 20px;
              vertical-align: middle;
            }
            span:nth-child(1) {
              width: 4px;
              height: 20px;
              background-color: #33bcb5;
              margin-right: 10px;
            }
            span:nth-child(2) {
              font-size: 16px;
              margin-right: 10px;
            }
            span:nth-child(3) {
              font-size: 12px;
              margin-right: 10px;
            }
          }
          // .right{

          // }
        }
      }
      > img:nth-of-type(1) {
        position: absolute;
        top: 0px;
        left: 0px;
        width: 100%;
        height: 26px;
      }
      > img:nth-of-type(2) {
        position: absolute;
        width: 100%;
        height: 592px;
        top: 13px;
        left: 0px;
      }
      > img:nth-of-type(3) {
        top: 592px;
        left: 0px;
        position: absolute;
        width: 100%;
        height: 26px;
      }
    }
    .navBox {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 75px;
      img {
        width: 79px;
        height: 75px;
        margin-right: 10px;
      }
      .topInfo {
        height: 75px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        span {
          color: rgba(60, 220, 210, 1);
        }
        span:nth-of-type(1) {
          font-size: 36px;
          margin-bottom: 10px;
          font-weight: bold;
        }
        span:nth-of-type(2) {
          color: rgba(60, 220, 210, 0.5);
        }
      }
    }
  }
}
</style>
